const puppeteer = require('puppeteer-extra');
const WriteBlog = require('./write-blog');
const { chromePath } = require('./config.json');
const blog = process.argv.splice(2, 1)[0];

async function init(params) {
    let args = [
        '--start-maximized',
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-infobars',
        '--window-position=0,0',
        '--ignore-certifcate-errors',
        '--ignore-certifcate-errors-spki-list',
    ];
    const options = {
        args,
        executablePath: chromePath,
        defaultViewport: null,
        headless: false,
        ignoreHTTPSErrors: true,
        devtools: false
    };
    //打开浏览器
    browser = await puppeteer.launch(options);

    // 打开页面
    const writeBlog = new WriteBlog();

    switch (blog) {
        case 'yuedun':
            const page = await browser.newPage();
            const blogHtml = await writeBlog.yuedunBlog(page);//月盾
            break;
        case 'csdn':
            const page2 = await browser.newPage();
            await writeBlog.csdnBlog(page2);//csdn
            break;
        case 'juejin':
            const page3 = await browser.newPage();
            await writeBlog.juejinBlog(page3);//掘金
            break;
        case 'sifou':

            break;
        case 'infoq':

            break;
        case 'gzh':
            const page4 = await browser.newPage();
            await writeBlog.gongzhonghao(page4, blogHtml);//公众号
            break;
        default:
            break;
    }
}

init();